package com.cuit.controller;

import com.cuit.pojo.Patient;
import com.cuit.service.Impl.PatientServiceImpl;
import com.cuit.service.PatientService;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

public class PasswordChangeServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String old_password = req.getParameter("p_password");
        String new_password = req.getParameter("p_password1");
        Patient patient = (Patient)req.getSession().getAttribute("patient");
        String p_id = patient.getP_id();
        System.out.println(p_id);
        Patient patient1 = new Patient(p_id,old_password);
        PatientService patientService = new PatientServiceImpl();
        if(patientService.login(patient1)==null){
            System.out.println("原密码输入错误！！！");
            resp.sendRedirect("patient/personal_center2.jsp");
        }else{
            patientService.modifyPassword(p_id,new_password);
            resp.sendRedirect("patient/personal_center2.jsp");
            System.out.println("密码修改成功！！！");
        }
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}
